package com.scau.clothes.config;

import com.scau.clothes.config.interceptor.TokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MyWebMvcConfigure implements WebMvcConfigurer {
    @Autowired
    TokenInterceptor tokenInterceptor;
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("toLogin").setViewName("public/login");
        registry.addViewController("/").setViewName("public/index");
        registry.addViewController("/index").setViewName("public/index");
        registry.addViewController("cart").setViewName("cart");
        registry.addViewController("/chat").setViewName("chat");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration registration = registry.addInterceptor(tokenInterceptor);
        registration.addPathPatterns("/**")
                .excludePathPatterns("/test/**")
                .excludePathPatterns("/toLogin")
                .excludePathPatterns("/login")
                .excludePathPatterns("/")
                .excludePathPatterns("/index")
                .excludePathPatterns("/**/*.jpg")
                .excludePathPatterns("/**/*.js")
                .excludePathPatterns("/**/*.css")
                .excludePathPatterns("/error")
                .excludePathPatterns("/img/**");
    }
}
